<template>
	<view class="content">
		<!-- 该页面的图表均为自定义图表 -->
		<qiun-title-bar title="血压"/>
		<view class="charts-box">
		  <qiun-data-charts
		    type="mmHgtype"
		    :chartData="mmHgData"
		    background="none"
		  />
		</view>
		<qiun-title-bar title="心率"/>
		<view class="charts-box">
		  <qiun-data-charts
		    type="heartRatetype"
		    :chartData="heartRateData"
		    background="none"
		  />
		</view>
		<qiun-title-bar title="血氧"/>
		<view class="charts-box">
		  <qiun-data-charts
		    type="bloodOxygentype"
		    :chartData="heartRateData"
		    background="none"
		  />
		</view>
		<!-- <qiun-title-bar title="体温"/> -->
		<!-- <view class="charts-box">
		  <qiun-data-charts
		    type="bodyTemptype"
		    :chartData="bodyTempData"
		    background="none"
		  />
		</view> -->
	</view>
</template>

<script>
	export default {
		data() {
			return {
				mmHgData:{
				  categories: [],
				  series: [{
				    name: "高压",
					data: [
						
					]
				  }, {
				    name: "低压",
					data: [
						
					]
				  }]
				},
				heartRateData:{
				  categories: [
					  
				  ],
				  series: [{
				    name: "心率",
					data: [
						
					]
				  }]
				},
				bloodOxygenData:{
				  categories: [
					  
				  ],
				  series: [{
				    name: "血氧",
					data: [
						
					]
				  }]
				},
				bodyTempData:{
				  categories: [
					  
				  ],
				  series: [{
				    name: "体温",
				    // data: [30, 31, 32, 33, 34, 35, 36, 37, 38, 39]
					data: [
						
					]
				  }]
				},
			}
		},
		onLoad() {
			this.getTableData()
		},
		methods: {
			getTableData(){
				const imei = uni.getStorageSync('imei');
				uni.showLoading({
				    title: '努力加载中'
				});
				uni.request({
					url: 'http://pm.gxtimeloit.com:10035/api-smartWatch/v1/healthMonitorHis/find?imei='+imei, 
					method: 'POST',
					header: {
						'Content-Type': 'application/x-www-form-urlencoded',
						'X-Requested-With': 'xmlhttprequest'
					},
					success: (res) => {
						if(res.data.success == false){
							if(res.data.code == "1001"){//如果请求需要登录
								uni.redirectTo({
									 url: '/pages/user/login/index'
								});
							}
						}
						// 传入数据，绘制图表
						this.processData(res.data.body.data.data);
					},
					fail: (err) => {
						uni.showToast({
							title: "请求接口失败"
						})
					},
					complete: ()=> {
						uni.hideLoading();//隐藏 loading 提示框。
					}
				})
			},
			processData(data){
				// 遍历data数据
				data.forEach((item, index)=>{
					// 心跳高压
					this.mmHgData.series[0].data.push(item.bloodPressureH)
					// 心跳低压
					this.mmHgData.series[1].data.push(item.bloodPressureL)
					this.mmHgData.categories.push(index+1)
					// 血氧
					this.bloodOxygenData.series[0].data.push(item.bloodOxygen)
					this.bloodOxygenData.categories.push(index+1)
					// 心率
					this.heartRateData.series[0].data.push(item.heartRate)
					this.heartRateData.categories.push(index+1)
				})
			}
		}
	}
</script>

<style>
	.charts-box{
		width: 100%;
		height:300px;
		border-bottom: 1px solid #dbdbdb; 
	}
</style>
